package com.base.system.managedBean;

import java.util.Map;

import javax.faces.context.FacesContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.user.util.Browser;

import com.base.security.SecurityConst;
import com.base.security.entity.SecurityUser;
import com.base.system.managedBean.baseBean.BaseSecurityUserBean;

/**
 * 
 * This managed bean is generated automatically
 */
@ManagedBean(name = "system_editSecurityUserForWindowBean", scope = ManagedBeanScope.REQUEST)
public class EditSecurityUserForWindowBean extends BaseSecurityUserBean {
	Log logger = LogFactory.getLog(EditSecurityUserForWindowBean.class);
	@Inject
	FacesContext context;

	protected void initSpecialProperty() {
		Map<String, Object> session = context.getExternalContext()
				.getSessionMap();
		securityUser = (SecurityUser) session
				.get(SecurityConst.SELECT_ROW_DATA);
		this.getSecurityUserProperty();
	}

	@BeforeRender
	public void beforeRender(boolean isPostback) {
		if (!isPostback) {
			initSpecialProperty();
		}
	}

	@Action(id = "saveSecurityUser")
	public void saveSecurityUser() {
		securityUser = securityEntityManager.getUserById(userId.getValue()
				.toString());
		String username = securityUser.getUsername();
		setSecurityUserProperty();
		securityUser.setUsername(username);
		securityEntityManager.saveUser(securityUser);
		Browser
				.execClientScript("window.parent.gridReloadJsvar.fireEvent('click');");
	}

	@Action(id = "addCancel")
	public void addCancel() {
		Browser
				.execClientScript("window.parent.gridReloadJsvar.fireEvent('click');");
	}
}
